home *** CD-ROM | disk | FTP | other *** search
/ This Disc Bytes! / Power Computing - The Disc 2 - This Disc Bytes.ISO / mac / CodeWarrior 7 Lite for 68K / MacOS Support / Headers / Universal Headers / MixedMode.h < prev    next >
Text File  |  1995-07-06  |  11KB  |  374 lines

  1. /*
  2.      File:        MixedMode.h
  3.  
  4.      Contains:    Mixed Mode Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.1 in “MPW Latest” on ETO #18
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. */
  19.  
  20. #ifndef __MIXEDMODE__
  21. #define __MIXEDMODE__
  22.  
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27. /*    #include <ConditionalMacros.h>                                */
  28.  
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32.  
  33. #if PRAGMA_ALIGN_SUPPORTED
  34. #pragma options align=mac68k
  35. #endif
  36.  
  37. #if PRAGMA_IMPORT_SUPPORTED
  38. #pragma import on
  39. #endif
  40.  
  41.  
  42. enum {
  43.     kRoutineDescriptorVersion    = 7
  44. };
  45.  
  46. /* MixedModeMagic Magic Cookie/Trap number */
  47. enum {
  48.     _MixedModeMagic                = 0xAAFE
  49. };
  50.  
  51. /* Calling Conventions */
  52. typedef unsigned short CallingConventionType;
  53.  
  54.  
  55. enum {
  56.     kPascalStackBased            = (CallingConventionType)0,
  57.     kCStackBased                = (CallingConventionType)1,
  58.     kRegisterBased                = (CallingConventionType)2,
  59.     kD0DispatchedPascalStackBased = (CallingConventionType)8,
  60.     kD1DispatchedPascalStackBased = (CallingConventionType)12,
  61.     kD0DispatchedCStackBased    = (CallingConventionType)9,
  62.     kStackDispatchedPascalStackBased = (CallingConventionType)14,
  63.     kThinkCStackBased            = (CallingConventionType)5
  64. };
  65.  
  66. /* ISA Types */
  67. typedef SInt8 ISAType;
  68.  
  69.  
  70. enum {
  71.     kM68kISA                    = (ISAType)0,
  72.     kPowerPCISA                    = (ISAType)1
  73. };
  74.  
  75. /* RTA Types */
  76. typedef SInt8 RTAType;
  77.  
  78.  
  79. enum {
  80.     kOld68kRTA                    = (RTAType)(0 << 4),
  81.     kPowerPCRTA                    = (RTAType)(0 << 4),
  82.     kCFM68kRTA                    = (RTAType)(1 << 4)
  83. };
  84.  
  85. #if GENERATINGPOWERPC
  86. #define GetCurrentISA() ((ISAType) kPowerPCISA)
  87. #define GetCurrentRTA() ((RTAType) kPowerPCRTA)
  88. #else
  89. #define GetCurrentISA() ((ISAType) kM68kISA)
  90. #if GENERATINGCFM
  91. #define GetCurrentRTA() ((RTAType) kCFM68kRTA)
  92. #else
  93. #define GetCurrentRTA() ((RTAType) kOld68kRTA)
  94. #endif
  95. #endif
  96. #define GetCurrentArchitecture() (GetCurrentISA() | GetCurrentRTA())
  97. enum {
  98.     kRegisterD0                    = 0,
  99.     kRegisterD1                    = 1,
  100.     kRegisterD2                    = 2,
  101.     kRegisterD3                    = 3,
  102.     kRegisterD4                    = 8,
  103.     kRegisterD5                    = 9,
  104.     kRegisterD6                    = 10,
  105.     kRegisterD7                    = 11,
  106.     kRegisterA0                    = 4,
  107.     kRegisterA1                    = 5,
  108.     kRegisterA2                    = 6,
  109.     kRegisterA3                    = 7,
  110.     kRegisterA4                    = 12,
  111.     kRegisterA5                    = 13,
  112.     kRegisterA6                    = 14,
  113. /* A7 is the same as the PowerPC SP */
  114.     kCCRegisterCBit                = 16,
  115.     kCCRegisterVBit                = 17,
  116.     kCCRegisterZBit                = 18,
  117.     kCCRegisterNBit                = 19,
  118.     kCCRegisterXBit                = 20
  119. };
  120.  
  121. typedef unsigned short registerSelectorType;
  122.  
  123. /* SizeCodes we use everywhere */
  124.  
  125. enum {
  126.     kNoByteCode                    = 0,
  127.     kOneByteCode                = 1,
  128.     kTwoByteCode                = 2,
  129.     kFourByteCode                = 3
  130. };
  131.  
  132. /* Mixed Mode Routine Records */
  133. typedef unsigned long ProcInfoType;
  134.  
  135. /* Routine Flag Bits */
  136. typedef unsigned short RoutineFlagsType;
  137.  
  138.  
  139. enum {
  140.     kProcDescriptorIsAbsolute    = (RoutineFlagsType)0x00,
  141.     kProcDescriptorIsRelative    = (RoutineFlagsType)0x01
  142. };
  143.  
  144. enum {
  145.     kFragmentIsPrepared            = (RoutineFlagsType)0x00,
  146.     kFragmentNeedsPreparing        = (RoutineFlagsType)0x02
  147. };
  148.  
  149. enum {
  150.     kUseCurrentISA                = (RoutineFlagsType)0x00,
  151.     kUseNativeISA                = (RoutineFlagsType)0x04
  152. };
  153.  
  154. enum {
  155.     kPassSelector                = (RoutineFlagsType)0x0,
  156.     kDontPassSelector            = (RoutineFlagsType)0x08
  157. };
  158.  
  159. enum {
  160.     kRoutineIsNotDispatchedDefaultRoutine = (RoutineFlagsType)0x0,
  161.     kRoutineIsDispatchedDefaultRoutine = (RoutineFlagsType)0x10
  162. };
  163.  
  164. struct RoutineRecord {
  165.     ProcInfoType                    procInfo;                    /* calling conventions */
  166.     UInt8                            reserved1;                    /* Must be 0 */
  167.     ISAType                            ISA;                        /* Instruction Set Architecture */
  168.     RoutineFlagsType                routineFlags;                /* Flags for each routine */
  169.     ProcPtr                            procDescriptor;                /* Where is the thing we’re calling? */
  170.     UInt32                            reserved2;                    /* Must be 0 */
  171.     UInt32                            selector;                    /* For dispatched routines, the selector */
  172. };
  173. typedef struct RoutineRecord RoutineRecord;
  174.  
  175. typedef RoutineRecord *RoutineRecordPtr, **RoutineRecordHandle;
  176.  
  177. /* Mixed Mode Routine Descriptors */
  178. /* Definitions of the Routine Descriptor Flag Bits */
  179. typedef UInt8 RDFlagsType;
  180.  
  181.  
  182. enum {
  183.     kSelectorsAreNotIndexable    = (RDFlagsType)0x00,
  184.     kSelectorsAreIndexable        = (RDFlagsType)0x01
  185. };
  186.  
  187. /* Routine Descriptor Structure */
  188. struct RoutineDescriptor {
  189.     UInt16                            goMixedModeTrap;            /* Our A-Trap */
  190.     SInt8                            version;                    /* Current Routine Descriptor version */
  191.     RDFlagsType                        routineDescriptorFlags;        /* Routine Descriptor Flags */
  192.     UInt32                            reserved1;                    /* Unused, must be zero */
  193.     UInt8                            reserved2;                    /* Unused, must be zero */
  194.     UInt8                            selectorInfo;                /* If a dispatched routine, calling convention, else 0 */
  195.     UInt16                            routineCount;                /* Number of routines in this RD */
  196.     RoutineRecord                    routineRecords[1];            /* The individual routines */
  197. };
  198. typedef struct RoutineDescriptor RoutineDescriptor;
  199.  
  200. typedef RoutineDescriptor *RoutineDescriptorPtr, **RoutineDescriptorHandle;
  201.  
  202. #define BUILD_ROUTINE_DESCRIPTOR(procInfo, procedure)  \
  203.     {                                \
  204.     _MixedModeMagic,                \
  205.     kRoutineDescriptorVersion,        \
  206.     kSelectorsAreNotIndexable,        \
  207.     0,                                \
  208.     0,                                \
  209.     0,                                \
  210.     0,                                \
  211.     {                                \
  212.     {                                \
  213.     (procInfo),                    \
  214.     0,                                \
  215.     GetCurrentArchitecture(),     \
  216.     kProcDescriptorIsAbsolute |     \
  217.     kFragmentIsPrepared |            \
  218.     kUseNativeISA,                    \
  219.     (ProcPtr)(procedure),            \
  220.     0,                                \
  221.     0                                \
  222.     }                                \
  223.     }                                \
  224.     }
  225. #define BUILD_FAT_ROUTINE_DESCRIPTOR(m68kProcInfo, m68kProcPtr, powerPCProcInfo, powerPCProcPtr)  \
  226.     {                                \
  227.     _MixedModeMagic,                \
  228.     kRoutineDescriptorVersion,        \
  229.     kSelectorsAreNotIndexable,        \
  230.     0,                                \
  231.     0,                                \
  232.     0,                                \
  233.     1,                                \
  234.     {                                \
  235.     {                                \
  236.     (m68kProcInfo),                \
  237.     0,                                \
  238.     kM68kISA |                        \
  239.     kOld68kRTA,                    \
  240.     kProcDescriptorIsAbsolute |     \
  241.     kUseCurrentISA,                \
  242.     (ProcPtr)(m68kProcPtr),        \
  243.     0,                                \
  244.     0,                                \
  245.     },                                \
  246.     {                                \
  247.     (powerPCProcInfo),                \
  248.     0,                                \
  249.     GetCurrentArchitecture(),     \
  250.     kProcDescriptorIsAbsolute |     \
  251.     kFragmentIsPrepared |            \
  252.     kUseCurrentISA,                \
  253.     (ProcPtr)(powerPCProcPtr),        \
  254.     0,                                \
  255.     0                                \
  256.     }                                \
  257.     }                                \
  258.     }
  259.  
  260. enum {
  261. /* Calling Convention Offsets */
  262.     kCallingConventionWidth        = 4,
  263.     kCallingConventionPhase        = 0,
  264.     kCallingConventionMask        = 0xF,
  265. /* Result Offsets */
  266.     kResultSizeWidth            = 2,
  267.     kResultSizePhase            = kCallingConventionWidth,
  268.     kResultSizeMask                = 0x30,
  269. /* Parameter offsets & widths */
  270.     kStackParameterWidth        = 2,
  271.     kStackParameterPhase        = (kCallingConventionWidth + kResultSizeWidth),
  272.     kStackParameterMask            = 0xFFFFFFC0,
  273. /* Register Result Location offsets & widths */
  274.     kRegisterResultLocationWidth = 5,
  275.     kRegisterResultLocationPhase = (kCallingConventionWidth + kResultSizeWidth),
  276. /* Register Parameter offsets & widths */
  277.     kRegisterParameterWidth        = 5,
  278.     kRegisterParameterPhase        = (kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth),
  279.     kRegisterParameterMask        = 0x7FFFF800,
  280.     kRegisterParameterSizePhase    = 0,
  281.     kRegisterParameterSizeWidth    = 2,
  282.     kRegisterParameterWhichPhase = kRegisterParameterSizeWidth,
  283.     kRegisterParameterWhichWidth = 3,
  284. /* Dispatched Stack Routine Selector offsets & widths */
  285.     kDispatchedSelectorSizeWidth = 2,
  286.     kDispatchedSelectorSizePhase = (kCallingConventionWidth + kResultSizeWidth),
  287. /* Dispatched Stack Routine Parameter offsets */
  288.     kDispatchedParameterPhase    = (kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth),
  289. /* Special Case offsets & widths */
  290.     kSpecialCaseSelectorWidth    = 6,
  291.     kSpecialCaseSelectorPhase    = kCallingConventionWidth,
  292.     kSpecialCaseSelectorMask    = 0x3F0,
  293. /* Component Manager Special Case offsets & widths */
  294.     kComponentMgrResultSizeWidth = 2,
  295.     kComponentMgrResultSizePhase = kCallingConventionWidth + kSpecialCaseSelectorWidth, /* 4 + 6 = 10 */
  296.     kComponentMgrParameterWidth    = 2,
  297.     kComponentMgrParameterPhase    = kComponentMgrResultSizePhase + kComponentMgrResultSizeWidth /* 10 + 2 = 12 */
  298. };
  299.  
  300. #define SIZE_CODE(size)         \
  301.     (((size) == 4) ? kFourByteCode : (((size) == 2) ? kTwoByteCode : (((size) == 1) ? kOneByteCode : 0)))
  302. #define RESULT_SIZE(sizeCode)     \
  303.     ((ProcInfoType)(sizeCode) << kResultSizePhase)
  304. #define STACK_ROUTINE_PARAMETER(whichParam, sizeCode)  \
  305.     ((ProcInfoType)(sizeCode) << (kStackParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  306. #define DISPATCHED_STACK_ROUTINE_PARAMETER(whichParam, sizeCode)  \
  307.     ((ProcInfoType)(sizeCode) << (kDispatchedParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  308. #define DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(sizeCode)  \
  309.     ((ProcInfoType)(sizeCode) << kDispatchedSelectorSizePhase)
  310. #define REGISTER_RESULT_LOCATION(whichReg)  \
  311.     ((ProcInfoType)(whichReg) << kRegisterResultLocationPhase)
  312. #define REGISTER_ROUTINE_PARAMETER(whichParam, whichReg, sizeCode)  \
  313.     ((((ProcInfoType)(sizeCode) << kRegisterParameterSizePhase) | ((ProcInfoType)(whichReg) << kRegisterParameterWhichPhase)) <<  \
  314.     (kRegisterParameterPhase + (((whichParam) - 1) * kRegisterParameterWidth)))
  315. #define COMPONENT_MGR_RESULT_SIZE(sizeCode)  \
  316.     ((ProcInfoType)(sizeCode) << kComponentMgrResultSizePhase)
  317. #define COMPONENT_MGR_PARAMETER(whichParam, sizeCode)  \
  318.     ((ProcInfoType)(sizeCode) << (kComponentMgrParameterPhase + (((whichParam) - 1) * kComponentMgrParameterWidth)))
  319. #define SPECIAL_CASE_PROCINFO(specialCaseCode)  \
  320.     (kSpecialCase | ((ProcInfoType)(specialCaseCode) << 4))
  321. enum {
  322.     kSpecialCase                = (CallingConventionType)0x0000000F
  323. };
  324.  
  325. enum {
  326. /* all of the special cases enumerated.  The selector field is 6 bits wide */
  327.     kSpecialCaseHighHook        = 0,
  328.     kSpecialCaseCaretHook        = 0,                            /* same as kSpecialCaseHighHook */
  329.     kSpecialCaseEOLHook            = 1,
  330.     kSpecialCaseWidthHook        = 2,
  331.     kSpecialCaseTextWidthHook    = 2,                            /* same as kSpecialCaseWidthHook */
  332.     kSpecialCaseNWidthHook        = 3,
  333.     kSpecialCaseDrawHook        = 4,
  334.     kSpecialCaseHitTestHook        = 5,
  335.     kSpecialCaseTEFindWord        = 6,
  336.     kSpecialCaseProtocolHandler    = 7,
  337.     kSpecialCaseSocketListener    = 8,
  338.     kSpecialCaseTERecalc        = 9,
  339.     kSpecialCaseTEDoText        = 10,
  340.     kSpecialCaseGNEFilterProc    = 11,
  341.     kSpecialCaseMBarHook        = 12,
  342.     kSpecialCaseComponentMgr    = 13
  343. };
  344.  
  345. #if GENERATINGCFM
  346. extern pascal UniversalProcPtr NewRoutineDescriptor(ProcPtr theProc, ProcInfoType theProcInfo, ISAType theISA)
  347.  TWOWORDINLINE(0x7000, 0xAA59);
  348. extern pascal void DisposeRoutineDescriptor(UniversalProcPtr theProcPtr)
  349.  TWOWORDINLINE(0x7001, 0xAA59);
  350. extern pascal UniversalProcPtr NewFatRoutineDescriptor(ProcPtr theM68kProc, ProcPtr thePowerPCProc, ProcInfoType theProcInfo)
  351.  TWOWORDINLINE(0x7002, 0xAA59);
  352. #else
  353. #define DisposeRoutineDescriptor(theProcPtr)
  354. #define NewRoutineDescriptor(theProc, theProcInfo, theISA) ((UniversalProcPtr)theProc)
  355. #endif
  356. #if CFMSYSTEMCALLS
  357. extern long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
  358. extern long CallOSTrapUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
  359. #endif
  360.  
  361. #if PRAGMA_IMPORT_SUPPORTED
  362. #pragma import off
  363. #endif
  364.  
  365. #if PRAGMA_ALIGN_SUPPORTED
  366. #pragma options align=reset
  367. #endif
  368.  
  369. #ifdef __cplusplus
  370. }
  371. #endif
  372.  
  373. #endif /* __MIXEDMODE__ */
  374.